package com.lyfei.yd.admin.web;

import com.lyfei.yd.common.core.domain.AjaxResult;
import com.lyfei.yd.system.domain.entity.BannerItem;
import com.lyfei.yd.system.service.BannerItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bannerItem")
public class BannerItemController {
    @Autowired
    private BannerItemService bannerItemService;

    @GetMapping("/{id}")
    public AjaxResult getBannerItem(@PathVariable Long id) {
        return AjaxResult.success(bannerItemService.getById(id));
    }

    @PostMapping("/saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody BannerItem bannerItem) {
        if(!bannerItemService.saveOrUpdate(bannerItem)) {
            return AjaxResult.error("保存失败");
        }

        return AjaxResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Long id) {

        if(!bannerItemService.removeById(id)) {
            return AjaxResult.error("删除失败");
        }

        return AjaxResult.success();
    }
}
